package com.ruoyi.purchase.controller;

import com.ruoyi.purchase.domain.FirmInventory;
import com.ruoyi.purchase.service.IFirmInventoryService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存管理Controller
 * 
 * @author ruoyi
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/inventory")
public class FirmInventoryController extends BaseController
{
    @Autowired
    private IFirmInventoryService firmInventoryService;

    /**
     * 查询库存管理列表
     */
    @RequiresPermissions("purchase:inventory:list")
    @GetMapping("/list")
    public TableDataInfo list(FirmInventory firmInventory)
    {
        startPage();
        List<FirmInventory> list = firmInventoryService.selectFirmInventoryList(firmInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @RequiresPermissions("purchase:inventory:export")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirmInventory firmInventory)
    {
        List<FirmInventory> list = firmInventoryService.selectFirmInventoryList(firmInventory);
        ExcelUtil<FirmInventory> util = new ExcelUtil<FirmInventory>(FirmInventory.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @RequiresPermissions("purchase:inventory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(firmInventoryService.selectFirmInventoryById(id));
    }

    /**
     * 新增库存管理
     */
    @RequiresPermissions("purchase:inventory:add")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirmInventory firmInventory)
    {
        return toAjax(firmInventoryService.insertFirmInventory(firmInventory));
    }

    /**
     * 修改库存管理
     */
    @RequiresPermissions("purchase:inventory:edit")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirmInventory firmInventory)
    {
        return toAjax(firmInventoryService.updateFirmInventory(firmInventory));
    }

    /**
     * 删除库存管理
     */
    @RequiresPermissions("purchase:inventory:remove")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(firmInventoryService.deleteFirmInventoryByIds(ids));
    }
}
